package com.payfen.client.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.payfen.client.jsonbean.ResultBean;
import com.payfen.util.FileTool;
import com.payfen.util.SecurityTool;

@Controller
public class ClientShopsUserInfAction extends Action {

	@RequestMapping(value = "/shopsUserLogin", method = RequestMethod.POST)
	public void shopsUserLogin(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		String msg = "";
		try {
			String merchantId = getRequestParameter(request, "merchantId");
			String userName = getRequestParameter(request, "userName");
			String userPwd = getRequestParameter(request, "userPwd");

			userPwd = SecurityTool.loginEncrypt(userPwd);

			if (merchantId != null && !merchantId.trim().equals("")
					&& userName != null && !userName.trim().equals("")
					&& userPwd != null && !userPwd.trim().equals("")) {
//				msg = ResultBean.createReturnJson("0000", "登录成功",null);
				msg = "{\"resultHead\"：{\"resultCode\"：\"0000\"，\"message\"：\"操作成功\"}," +
						"\"resultBody\"：{\"body\":{\"shopId\":\"010001\",\"shopName\":\"首都机场店\"}}}";
			} else {
				msg = ResultBean.createReturnJson("0001", FileTool.getErrorCodeFromProperties("0001"),null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			msg = ResultBean.createReturnJson("0002", FileTool.getErrorCodeFromProperties("0002"),null);
		}
		out.write(msg);
		out.flush();
		out.close();
	}

	@RequestMapping(value = "/shopsUserAdd", method = RequestMethod.POST)
	public void shopsUserAdd(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		String msg = "";
		try {
			String merchantId = getRequestParameter(request, "merchantId");
			String adminName = getRequestParameter(request, "adminName");
			String adminPwd = getRequestParameter(request, "adminPwd");
			String userName = getRequestParameter(request, "userName");

			// userPwd = SecurityTool.loginEncrypt(userPwd);

			if (merchantId != null && !merchantId.trim().equals("") && adminName != null && !adminName.trim().equals("")
					&& adminPwd != null && !adminPwd.trim().equals("") && userName != null && !userName.trim().equals("")) {
				msg = ResultBean.createReturnJson("0000", "操作成功",null);
			} else {
				msg = ResultBean.createReturnJson("0004", FileTool.getErrorCodeFromProperties("0002"),null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			msg = ResultBean.createReturnJson("0002", FileTool.getErrorCodeFromProperties("0002"),null);
		}
		out.write(msg);
		out.flush();
		out.close();
	}

	@RequestMapping(value = "/shopsUserUpdatePwd", method = RequestMethod.POST)
	public void shopsUserUpdatePwd(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();

		String msg = "";
		try {
			String merchantId = getRequestParameter(request, "merchantId");
			String adminName = getRequestParameter(request, "adminName");
			String adminPwd = getRequestParameter(request, "adminPwd");
			String userName = getRequestParameter(request, "userName");
			String userOldPwd = getRequestParameter(request, "userOldPwd");
			String userNewPwd = getRequestParameter(request, "userNewPwd");

			// userPwd = SecurityTool.loginEncrypt(userPwd);

			if (merchantId != null && !merchantId.trim().equals("") && adminName != null && !adminName.trim().equals("")
					&& adminPwd != null && !adminPwd.trim().equals("") && userName != null && !userName.trim().equals("")
					&& userOldPwd != null && !userOldPwd.trim().equals("") && userNewPwd != null && !userNewPwd.trim().equals("")) {
				msg = ResultBean.createReturnJson("0000", "操作成功",null);
			} else {
				msg = ResultBean.createReturnJson("0004", FileTool.getErrorCodeFromProperties("0002"),null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			msg = ResultBean.createReturnJson("0002", FileTool.getErrorCodeFromProperties("0002"),null);
		}
		out.write(msg);
		out.flush();
		out.close();
	}

}
